﻿using Net7Docker.Jobs;
using Newtonsoft.Json.Linq;
using Quartz;

namespace Net7Docker.Extensions
{
    public static class QuartzSetup
    {
        public static void AddQuartz(this WebApplicationBuilder builder)
        {
            builder.Services.AddQuartz(options =>
            {
                options.UseMicrosoftDependencyInjectionJobFactory();

                //job配置提取
                //var jobkey = JobKey.Create(nameof(MyJob));
                //options
                //    .AddJob<MyJob>(jobkey)
                //    .AddTrigger(trigger =>
                //       trigger.ForJob(jobkey)
                //              .WithSimpleSchedule(schedule =>
                //                  schedule.WithIntervalInSeconds(5).RepeatForever()));

            });

            builder.Services.AddQuartzHostedService(options =>
            {
                //应用程序关闭时等待所有job完成
                options.WaitForJobsToComplete = true;
            });

            //注入job配置
            builder.Services.ConfigureOptions<MyJobSetup>();

        }
    }
}
